// pages/member/rankingListSecond/rankingListSecond.js
var app = getApp();
Page({

  /**
	 * 页面的初始数据
	 */
  data: {
    language: '',
    integral: 0,
    transfer_set: 0,
    withdraw_set_title: 0,
    name: "",
    ios_virtual_pay: false,
    is_transformation: '',
    love_name: '',
    is_transformation_point:false,
    point_name:''
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function(options) {
    try {
      // 推广中心是否开启该功能，没开启跳转到指定路径
      let basic_info = wx.getStorageSync("yz_basic_info");
      let stop_info = basic_info.popularize_page.mini.vue_route;
      for (let i = 0; i < stop_info.length; i++) {
        if (stop_info[i] == 'Integral_love') {
          console.log(basic_info.popularize_page.mini.mini_url + "跳转的路径");

          wx.showToast({
            title: '未开启推广权限',
            duration: 2000,
            icon: 'none',
            success: function() {
              setTimeout(() => {
                wx.redirectTo({
                  url: basic_info.popularize_page.mini.mini_url,
                });
              }, 1000);
            }
          });
          return;
        }
      }
    } catch (e) {
      console.log(e);
    }
    this.getName();
    this.getData();
    try {
      var value = wx.getStorageSync('ios_virtual_pay');
      if (value) {
        this.setData({
          ios_virtual_pay:value
        });
      }
    } catch (e) {
      console.log(e);
    }
  },

  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  onReady: function() {
    let language = wx.getStorageSync('langIndex');
    this.setData({ 'language': language.en});
  },

  /**
	 * 生命周期函数--监听页面显示
	 */
  onShow: function() {
    this.getData();
  },

  /**
	 * 生命周期函数--监听页面隐藏
	 */
  onHide: function() {

  },

  /**
	 * 生命周期函数--监听页面卸载
	 */
  onUnload: function() {

  },

  /**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
  onPullDownRefresh: function() {

  },

  /**
	 * 页面上拉触底事件的处理函数
	 */
  onReachBottom: function() {

  },

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function() {

  },
  getName() {
    let urlStr = app.getNetAddresss("plugin.integral.Frontend.Controllers.page.get-name");
    app._getNetWork({
      url: urlStr,
      success: (response) => {
        let resData = response.data;
        if (resData.result === 1) {
          this.setData({
            name: resData.data
          });
        } else {
          wx.showToast({
            title: resData.msg,
            icon: 'none',
            duration: 2000
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  getData() {
    let urlStr = app.getNetAddresss("plugin.integral.Frontend.Controllers.Page.index");
    app._getNetWork({
      url: urlStr,
      success: (response) => {
        let resData = response.data;
        if (resData.result === 1) {
          this.setData({
            integral: resData.data.member_integral,
            transfer_set: resData.data.transfer_set,
            is_transformation: resData.data.is_transformation,
            love_name: resData.data.love_name,
            withdraw_set_title: resData.data.withdraw_set_title,
            manual_withdraw_set_switch:resData.data.manual_withdraw_set_switch,
            is_recharge:resData.data.is_recharge.is_recharge
          });
          if(resData.data.is_transformation_point){
            this.setData({
              point_name:resData.data.point_name,
              is_transformation_point:resData.data.is_transformation_point
            })
          }
        } else {
          wx.showToast({
            title: resData.msg,
            icon: 'none',
            duration: 2000
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  // 跳转页面
  gotoPage(e) {
    var url = e.target.dataset.url || e.currentTarget.dataset.url;
    if (url == 'Integral_invest' && this.data.ios_virtual_pay) {
      wx.showModal({
        title: '提示',
        content: '十分抱歉，由于相关规定，你暂时无法在这里充值！',
        confirmText: '知道了',
        showCancel: false,
        success(res) {}
      });
      return false;
    }
    if(url == 'Integral_change2'){
      wx.navigateTo({
        url: '/packageB/member/Integral_change/Integral_change?type=shift'
      });
      return
    }
    if (url == 'overseas_explain') {
      this.setData({
        show: true
      });
      return;
    }
    if(url == "handWithdraw"){
      wx.navigateTo({
        url: '/packageB/member/handWithdraw/handWithdraw',
      });
      return;
    }
    wx.navigateTo({
      url: '/packageB/member/' + url + '/' + url
    });
  },
  onClickLeft() {
    this.setData({
      show: false
    });
  },
  onClickRight() {
    wx.navigateTo({
      url: "/packageB/member/Integral_love_detail/Integral_love_detail"
    });
  }

});
